import { makeAutoObservable } from "mobx";
import React from "react";
import * as apis from "@shared/apis";

export class PageController {

    static Context = React.createContext<PageController>(undefined as any);

    /** 服务ID */
    id = '';

    /** 服务详情 */
    data?: apis.services.IServices;

    constructor() {
        makeAutoObservable(this);
    }

    /** 设置服务ID */
    setId = (id: string) => {
        this.id = id;
    }

    /** 查询指定页码的数据 */
    query = async () => {
        try {
            if (this.id) {
                this.data = await apis.services.detail.get(this.id);
            } else {
                this.data = undefined
            }
        } catch (error) {
            this.data = undefined;
            console.log(error);
        }
    }
} 